package com.qf.exception;

import com.sun.org.apache.regexp.internal.RE;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ExceptionHandler implements HandlerExceptionResolver {
    Logger logger = Logger.getLogger(ExceptionHandler.class);

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView = new ModelAndView();
        //未登录
        if (e instanceof LoginException) {
            modelAndView.setViewName("redirect:/html/login");
//            modelAndView.setViewName("login");
            return modelAndView;
        }
        //权限不够
        if (e instanceof PermissionException) {
//            modelAndView.setViewName("nopermission");
            modelAndView.setViewName("redirect:/html/nopermission");
            return modelAndView;
        }
        return null;
    }
}
